home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / MEMALLOC.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-09-29  |  3.6 KB  |  138 lines

  1. comment $*********************************************************************
  2.  
  3.              MEMALLOC.ASM
  4.  
  5.     Example using Peter Anderson's memory routines. DOS32 supports basic
  6. memory manigment routines which are limited in a number of ways.
  7. * No ore than 64 allocations should be made.
  8. * Sizes are restriced to multiple of 4Kb blocks.
  9. * They are relativly slow.
  10.  
  11. Peter's memory sub routines are in directory \pal\malloc\. These were
  12. written for C applications are also ideal for use in pure ASM programs.
  13. They will allow your programs to handle memory manigment
  14. much more efficently than just the using DOS32 allocation routines.
  15. Please read the README.TXT and the ASM files for more information of
  16. using these functions. Below is a list of all the nessaccary files from 
  17. PAL you will need to link;
  18.  
  19. malloc.obj
  20. setmem.obj
  21. memory.obj
  22. calloc.obj   (optional)
  23. resize.obj   (optional)
  24. free.obj     (optional)
  25. realloc.obj  (optional)
  26. memcpy.obj   (optional)
  27. memset.obj   (optional)
  28.  
  29. You may wan to combine all these obj files into a small libray file so
  30. it easier and quicker to link in them.
  31.  
  32.     To build this program...
  33.  
  34.  tasm memalloc
  35.  dlink -c memalloc memory free setmem malloc resize
  36.  
  37. Good luck.
  38. *************************************************************************** $
  39.  
  40. .386
  41.  
  42. .MODEL FLAT, C                                  ; Define segments.
  43.  
  44. .STACK 1000h                                    ; Define initial stack.
  45.  
  46. .CODE
  47.  
  48. MemPtr    DD ?
  49. intro_mesg LABEL BYTE
  50. DB "MEMALLOC.EXE: example program using the sub-memory functions from",13,10
  51. DB "              the PAL library. See source for info",13,10,36
  52. exit_mesg  LABEL BYTE
  53. DB " Everthing was successful ",13,10,36
  54.  
  55.  
  56. ;
  57. ; Define externals of all PAL memory routines.
  58. ;
  59. extrn NoLanguage @malloc :Near
  60. extrn NoLanguage @setmem :Near
  61. extrn NoLanguage @free   :Near
  62. extrn NoLanguage @realloc:Near
  63. extrn NoLanguage @calloc :Near
  64. extrn NoLanguage @resize :Near
  65. extrn NoLanguage @maxavail:Near
  66. extrn NoLanguage @memset :Near
  67. extrn NoLanguage @memcpy :Near
  68.  
  69.  
  70. My_program:                                     ; Start of program
  71.  
  72.     ; print a message to output
  73.         mov edx,Offset intro_mesg
  74.         mov ah,9
  75.         int 21h
  76.  
  77.  
  78.  ; Allocate a single DOS32 system memory block. This is the memory pool
  79.  ; that the malloc routines will use. Please read README.TXT for more
  80.  ; information on the @setmem function.
  81.  ;
  82.         mov edx,-1
  83.         mov ax,0EE42h
  84.         int 31h                                ; Returns EDX -> block, EAX = size
  85.         Test eax,eax
  86.         jz @@ErrorExit
  87.  
  88.         xchg eax,edx
  89.         call @setmem
  90.  
  91.  
  92. ;******* The PAL memory routines now ready for the application to use ******
  93.  
  94.      ;--------- Allocate 100Kb ------------
  95.         mov     eax,1024*100
  96.         call    @malloc
  97.         Test    eax,eax
  98.         jz      @@ErrorExit
  99.         mov    [MemPtr],eax
  100.  
  101.      ;--------- Resize block to 77Kb  ------------
  102.         mov     eax,[MemPtr]
  103.         mov     edx,77*1024
  104.         call    @resize
  105.         Test    eax,eax
  106.         jz      @@ErrorExit
  107.  
  108.      ;--------- Free  ------------
  109.         mov     eax,[MemPtr]
  110.         call    @free
  111.  
  112.  
  113.      ;--------- print mesg  ------------
  114.         mov edx,Offset exit_mesg
  115.         mov ah,9
  116.         int 21h
  117.  
  118.  
  119.      ;--------- Exit program  ------------
  120.  
  121. Exit:
  122.         mov   ax,4C00h                          ; Termiate the program
  123.         int   21h
  124.  
  125.  
  126.         ;----- print an error mesage --------
  127. err_msg db 'An error happened',13,10,36
  128.  
  129. @@ErrorExit:
  130.         mov edx,Offset err_msg
  131.         mov ah,9
  132.         int 21h
  133.         jmp Exit
  134.  
  135.  
  136. END  My_program
  137.  
  138.